package com.huike.web.controller.review;



import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 该Controller主要是为了复习三层架构以及Mybatis使用的，该部分接口已经放开权限，可以直接访问
 * 同学们在此处编写接口通过浏览器访问看是否能完成最简单的增删改查
 */
@RestController
@RequestMapping("/review")
public class MybatisReviewController extends BaseController {

    @Autowired
    private ReviewService reviewService;

    @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult add(@PathVariable String name, @PathVariable int age, @PathVariable String sex){

        int i = reviewService.add(name, age, sex);

        return AjaxResult.success("添加插入"+i+"条数据");
    }

    @PostMapping("/saveData")
    public AjaxResult addReview(@RequestBody Review review){

        int i = reviewService.addReview(review);

        return AjaxResult.success("添加插入"+i+"条数据");
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody Review review){

        reviewService.update(review);
        return AjaxResult.success("修改成功");
    }
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable int id){
        reviewService.remove(id);

        return AjaxResult.success("删除成功");
    }

    @GetMapping("/getById")
    public AjaxResult getById(int id){
        Review review=reviewService.getById(id);

        return AjaxResult.success("操作成功",review);
    }

    @GetMapping("/getDataByPage")
    public TableDataInfo getDataByPage(){
        startPage();
        List<Review> reviewList =reviewService.getDataByPage();
        return getDataTable(reviewList);
    }
}